package com.usb.serial.device;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.TextView;

import java.util.List;

public class CustomDialog extends Dialog {

    private TextView titleTextView;
    private Spinner dropdownSpinner;
    private Button button1;
    private Button button2;

    public CustomDialog(Context context) {
        super(context);
        init();
    }

    public CustomDialog(Context context, int themeResId) {
        super(context, themeResId);
        init();
    }

    private void init() {
        setContentView(R.layout.dialog_windows);

//        titleTextView = findViewById(R.id.title);
//        dropdownSpinner = findViewById(R.id.dropdown);
//        button1 = findViewById(R.id.button1);
//        button2 = findViewById(R.id.button2);

        // 设置对话框的宽度和高度
        WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
        layoutParams.width = ViewGroup.LayoutParams.WRAP_CONTENT;
        layoutParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        getWindow().setAttributes(layoutParams);
    }

    public void setTitle(String title) {
        titleTextView.setText(title);
    }

    public void setDropdownOptions(List<String> options) {
        ArrayAdapter<String> adapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_item, options);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        dropdownSpinner.setAdapter(adapter);
    }


    public void setButton1ClickListener(View.OnClickListener listener) {
        button1.setOnClickListener(listener);
    }

    public void setButton2ClickListener(View.OnClickListener listener) {
        button2.setOnClickListener(listener);
    }
}